package cn.iocoder.yudao.module.hs.dal.mysql.material;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.hs.controller.admin.bigscreen.vo.WarehouseMaterialCount;
import cn.iocoder.yudao.module.hs.controller.admin.material.vo.MaterialModeRespVO;
import cn.iocoder.yudao.module.hs.controller.admin.material.vo.MaterialPageReqVO;
import cn.iocoder.yudao.module.hs.dal.dataobject.material.MaterialDO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 物料信息 Mapper
 *
 * @author 航盛
 */
@Mapper
public interface MaterialMapper extends BaseMapperX<MaterialDO> {

    default PageResult<MaterialDO> selectPage(MaterialPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<MaterialDO>()
                .likeIfPresent(MaterialDO::getName, reqVO.getName())
                .likeIfPresent(MaterialDO::getCode, reqVO.getCode())
                .eqIfPresent(MaterialDO::getModeCode, reqVO.getModeCode())
                .eqIfPresent(MaterialDO::getWarehouseId, reqVO.getWarehouseId())
                .eqIfPresent(MaterialDO::getBoxCode, reqVO.getBoxCode())
                .eqIfPresent(MaterialDO::getTrayCode, reqVO.getTrayCode())
                .eqIfPresent(MaterialDO::getStatus, reqVO.getStatus())
                .eqIfPresent(MaterialDO::getWorkOrderNo, reqVO.getWorkOrderNo())
                .eqIfPresent(MaterialDO::getQcResult, reqVO.getQcResult())
                .betweenIfPresent(MaterialDO::getWarehousingTime, reqVO.getWarehousingTime())
                .betweenIfPresent(MaterialDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(MaterialDO::getId));
    }

    default List<MaterialDO> selectListByTrayCode(String trayCode) {
        return selectList(MaterialDO::getTrayCode, trayCode);
    }

    IPage<MaterialModeRespVO> getMaterialModePage(IPage<MaterialModeRespVO> ipage, @Param("pageReqVO") MaterialPageReqVO pageReqVO);

    default List<MaterialDO> getMaterialsByModeCode(Long warehouseId, String materialModeCode) {
        return selectList(new LambdaQueryWrapperX<MaterialDO>()
                .eqIfPresent(MaterialDO::getWarehouseId, warehouseId)
                .likeIfPresent(MaterialDO::getModeCode, materialModeCode)
                .isNull(MaterialDO::getShipTime)
                .isNotNull(MaterialDO::getWarehousingTime));
    }

    List<WarehouseMaterialCount> getTripartiteMaterialChart();

    Integer getProductWarehouseCount();
}